/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author smile
 */
@Entity
@Table(name = "notes", catalog = "shortnotes", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Notes.findAll", query = "SELECT n FROM Notes n"),
    @NamedQuery(name = "Notes.findById", query = "SELECT n FROM Notes n WHERE n.id = :id"),
    @NamedQuery(name = "Notes.findByListId", query = "SELECT n FROM Notes n WHERE n.idList = :idList"),
    @NamedQuery(name = "Notes.findAllNotComplited", query = "SELECT n FROM Notes n WHERE n.idList = :idList AND n.isComplete = 0"),
    @NamedQuery(name = "Notes.findAllComplited", query = "SELECT n FROM Notes n WHERE n.idList = :idList AND n.isComplete = 1"),
    @NamedQuery(name = "Notes.updatePriorityByNote", query = "UPDATE Notes n SET n.isPriority = :isPriority WHERE n.id = :id"),
    @NamedQuery(name = "Notes.updateCompleteById", query = "UPDATE Notes n SET n.isComplete = :isComplete WHERE n.id = :id"),
    @NamedQuery(name = "Notes.updateExpiresDateById", query = "UPDATE Notes n SET n.dateExpires = :dateExpires WHERE n.id = :id"),
    @NamedQuery(name = "Notes.findByIsComplete", query = "SELECT n FROM Notes n WHERE n.isComplete = :isComplete"),
    @NamedQuery(name = "Notes.findByIsPriority", query = "SELECT n FROM Notes n WHERE n.isPriority = :isPriority"),
    @NamedQuery(name = "Notes.findByIsChanges", query = "SELECT n FROM Notes n WHERE n.isChanges = :isChanges"),
    @NamedQuery(name = "Notes.findExpiresNotes", query = "SELECT n FROM Notes n WHERE n.dateExpires IS NOT NULL AND n.dateExpires < n.dateOfPublication"),
    @NamedQuery(name = "Notes.findByDateOfPublication", query = "SELECT n FROM Notes n WHERE n.dateOfPublication = :dateOfPublication"),
    @NamedQuery(name = "Notes.findByDateExpires", query = "SELECT n FROM Notes n WHERE n.dateExpires = :dateExpires")})
public class Notes implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "id", nullable = false)
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Lob
    @Size(min = 1, max = 65535)
    @Column(name = "text", nullable = false, length = 65535)
    private String text;
    @Column(name = "is_complete")
    private Integer isComplete;
    @Column(name = "is_priority")
    private Integer isPriority;
    @Column(name = "is_changes")
    private Integer isChanges;
    @Column(name = "date_of_publication")
    @Temporal(TemporalType.DATE)
    private Date dateOfPublication;
    @Column(name = "date_expires")
    @Temporal(TemporalType.DATE)
    private Date dateExpires;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idNotes")
    private List<Description> descriptionList;
    @JoinColumn(name = "id_list", referencedColumnName = "id", nullable = false)
    @ManyToOne(optional = false)
    private Lists idList;

    public Notes() {
    }

    public Notes(Integer id) {
        this.id = id;
    }

    public Notes(Integer id, String text) {
        this.id = id;
        this.text = text;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public Integer getIsComplete() {
        return isComplete;
    }

    public void setIsComplete(Integer isComplete) {
        this.isComplete = isComplete;
    }

    public Integer getIsPriority() {
        return isPriority;
    }

    public void setIsPriority(Integer isPriority) {
        this.isPriority = isPriority;
    }

    public Integer getIsChanges() {
        return isChanges;
    }

    public void setIsChanges(Integer isChanges) {
        this.isChanges = isChanges;
    }

    public Date getDateOfPublication() {
        return dateOfPublication;
    }

    public void setDateOfPublication(Date dateOfPublication) {
        this.dateOfPublication = dateOfPublication;
    }

    public Date getDateExpires() {
        return dateExpires;
    }

    public void setDateExpires(Date dateExpires) {
        this.dateExpires = dateExpires;
    }

    @XmlTransient
    public List<Description> getDescriptionList() {
        return descriptionList;
    }

    public void setDescriptionList(List<Description> descriptionList) {
        this.descriptionList = descriptionList;
    }

    public Lists getIdList() {
        return idList;
    }

    public void setIdList(Lists idList) {
        this.idList = idList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Notes)) {
            return false;
        }
        Notes other = (Notes) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Notes[ id=" + id + " ]";
    }
    
}
